package members;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class MemberDelete extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {					
			
		try {
			String Mid= req.getParameter("delID");			
			Class.forName("org.h2.Driver");
			Connection con = DriverManager.getConnection("jdbc:h2:~/retail","sa", "");			
			PreparedStatement ps = con.prepareStatement("DELETE MEMBER WHERE MEMBERID= ?");
		    ps.setString(1, Mid);

		    ps.executeUpdate();
		    ps.close();
			con.close();
			resp.sendRedirect("Member/MemberMain.jsp");			
		}catch (SQLException e) {			
			req.setAttribute("b", "SQL Exception: Insert Error!");
			req.getRequestDispatcher("Member/MemberError.jsp").forward(req, resp);							
		}catch (NumberFormatException e){
			req.setAttribute("b", "SQL Exception: Input Error!");
			req.getRequestDispatcher("Member/MemberError.jsp").forward(req, resp);		
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
					
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		
	}

}
